/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-26
 * Time: 14:50
 */
public class Dome_1 {
    public static void main(String[] args) {
        System.out.println(getLongestPalindrome("ababc"));
    }

    public static int getLongestPalindrome(String str) {
        // write code here
        int maxsize = 0;
        int size = str.length();
        for (int i = 0; i < size; i++) {
            for (int j = size; j > i; j--) {
                String new_str = str.substring(i, j);
                int tmp = getLongPalindrome(new_str);
                if (maxsize <= tmp) {
                    maxsize = tmp;
                }
            }
        }
        return maxsize;
    }

    public static int getLongPalindrome(String str) {
        int size = str.length();
        int right = 0;
        int left = size - 1;
        while (right < left) {
            if (str.charAt(right) != str.charAt(left)) {
                return 0;
            }
            right++;
            left--;
        }
        return size;
    }
}
